<html>
<head><meta charset="utf-8"><title>llvm fork prototypes rust_alloc with 3 params · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20fork.20prototypes.20rust_alloc.20with.203.20params.html">llvm fork prototypes rust_alloc with 3 params</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="223948353"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20fork%20prototypes%20rust_alloc%20with%203%20params/near/223948353" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Hughes <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20fork.20prototypes.20rust_alloc.20with.203.20params.html#223948353">(Jan 25 2021 at 19:34)</a>:</h4>
<p>I was looking at how Rust's LLVM fork adds optimisation hints for Rust alloc functions and came across this:</p>
<div class="codehilite"><pre><span></span><code>case LibFunc_rust_alloc:
    return (NumParams == 3 &amp;&amp; FTy.getReturnType()-&gt;isPointerTy() &amp;&amp;
            FTy.getParamType(0)-&gt;isIntegerTy() &amp;&amp;
            FTy.getParamType(1)-&gt;isIntegerTy() &amp;&amp;
            FTy.getParamType(2)-&gt;isPointerTy());
</code></pre></div>
<p>/llvm/lib/Analysis/TargetLibraryInfo.cpp#L1493 (<a href="https://github.com/rust-lang/llvm-project/blob/f9a8d70b6e0365ac2172ca6b7f1de0341297458d/llvm/lib/Analysis/TargetLibraryInfo.cpp#L1493">https://github.com/rust-lang/llvm-project/blob/f9a8d70b6e0365ac2172ca6b7f1de0341297458d/llvm/lib/Analysis/TargetLibraryInfo.cpp#L1493</a>)</p>
<p>I don't understand why there are 3 param types in the conditional - doesn't <code>__rust_alloc</code> only take 2?</p>



<a name="223948764"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20fork%20prototypes%20rust_alloc%20with%203%20params/near/223948764" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Hughes <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20fork.20prototypes.20rust_alloc.20with.203.20params.html#223948764">(Jan 25 2021 at 19:37)</a>:</h4>
<p>Similarly, <code>rust_realloc</code> has 6 here:</p>
<div class="codehilite"><pre><span></span><code> case LibFunc_rust_realloc:
    return (NumParams == 6 &amp;&amp; FTy.getReturnType()-&gt;isPointerTy() &amp;&amp;
            FTy.getParamType(0)-&gt;isPointerTy() &amp;&amp;
            FTy.getParamType(1)-&gt;isIntegerTy() &amp;&amp;
            FTy.getParamType(2)-&gt;isIntegerTy() &amp;&amp;
            FTy.getParamType(3)-&gt;isIntegerTy() &amp;&amp;
            FTy.getParamType(4)-&gt;isIntegerTy() &amp;&amp;
            FTy.getParamType(5)-&gt;isPointerTy());
</code></pre></div>
<p>But the signature in rust is  <code>fn __rust_realloc(ptr: *mut u8, old_size: usize, align: usize, new_size: usize) -&gt; *mut u8;</code></p>
<p>I'm clearly missing something. Any pointers? :)</p>



<a name="223950141"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20fork%20prototypes%20rust_alloc%20with%203%20params/near/223950141" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20fork.20prototypes.20rust_alloc.20with.203.20params.html#223950141">(Jan 25 2021 at 19:49)</a>:</h4>
<p>oh my, it would be embarrassing if these have been so ineffective...</p>



<a name="223950295"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20fork%20prototypes%20rust_alloc%20with%203%20params/near/223950295" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20fork.20prototypes.20rust_alloc.20with.203.20params.html#223950295">(Jan 25 2021 at 19:50)</a>:</h4>
<p>you can see vestiges from the old alloc design here:<br>
<a href="https://github.com/rust-lang/rust/pull/49669/files#diff-0a8db664d0f1760d49f853d56f02d065a599a955cf46a664c9e9684ef1090231">https://github.com/rust-lang/rust/pull/49669/files#diff-0a8db664d0f1760d49f853d56f02d065a599a955cf46a664c9e9684ef1090231</a></p>



<a name="223950403"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20fork%20prototypes%20rust_alloc%20with%203%20params/near/223950403" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20fork.20prototypes.20rust_alloc.20with.203.20params.html#223950403">(Jan 25 2021 at 19:51)</a>:</h4>
<p><code>cfg(stage0)</code> being the old design for transition, to <code>cfg(not(stage0))</code> matching what we have today</p>



<a name="223950656"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20fork%20prototypes%20rust_alloc%20with%203%20params/near/223950656" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20fork.20prototypes.20rust_alloc.20with.203.20params.html#223950656">(Jan 25 2021 at 19:52)</a>:</h4>
<p><span class="user-mention" data-user-id="223286">@Jake Hughes</span> so yes, it looks like this should have been updated</p>



<a name="223951106"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20fork%20prototypes%20rust_alloc%20with%203%20params/near/223951106" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20fork.20prototypes.20rust_alloc.20with.203.20params.html#223951106">(Jan 25 2021 at 19:55)</a>:</h4>
<p><span class="user-mention" data-user-id="223286">@Jake Hughes</span> would you like to fix this yourself?</p>



<a name="223951922"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20fork%20prototypes%20rust_alloc%20with%203%20params/near/223951922" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Hughes <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20fork.20prototypes.20rust_alloc.20with.203.20params.html#223951922">(Jan 25 2021 at 20:00)</a>:</h4>
<p>Aha. I see!</p>



<a name="223951980"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20fork%20prototypes%20rust_alloc%20with%203%20params/near/223951980" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Hughes <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20fork.20prototypes.20rust_alloc.20with.203.20params.html#223951980">(Jan 25 2021 at 20:00)</a>:</h4>
<p>Sure, id be happy to.</p>



<a name="223970161"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20fork%20prototypes%20rust_alloc%20with%203%20params/near/223970161" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Hughes <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20fork.20prototypes.20rust_alloc.20with.203.20params.html#223970161">(Jan 25 2021 at 22:15)</a>:</h4>
<p>Hey <span class="user-mention" data-user-id="138448">@cuviper</span>  quick question: is there a way to trigger an incremental recompilation of in-tree LLVM through the x.py system? Or do I need to cd into the build dir and run make the old fashioned way?</p>



<a name="223970376"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20fork%20prototypes%20rust_alloc%20with%203%20params/near/223970376" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20fork.20prototypes.20rust_alloc.20with.203.20params.html#223970376">(Jan 25 2021 at 22:16)</a>:</h4>
<p>if you just remove <code>build/x86_64-unknown-linux-gnu/llvm/llvm-finished-building</code> (or whatever your host target), it should let cmake do an incremental build</p>



<a name="223970435"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20fork%20prototypes%20rust_alloc%20with%203%20params/near/223970435" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20fork.20prototypes.20rust_alloc.20with.203.20params.html#223970435">(Jan 25 2021 at 22:16)</a>:</h4>
<p>which isn't perfect, but usually works well enough for source changes</p>



<a name="223970474"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20fork%20prototypes%20rust_alloc%20with%203%20params/near/223970474" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Hughes <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20fork.20prototypes.20rust_alloc.20with.203.20params.html#223970474">(Jan 25 2021 at 22:16)</a>:</h4>
<p>aha, yep that'll do, thanks :)</p>



<a name="224120379"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20fork%20prototypes%20rust_alloc%20with%203%20params/near/224120379" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Hughes <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20fork.20prototypes.20rust_alloc.20with.203.20params.html#224120379">(Jan 26 2021 at 23:38)</a>:</h4>
<p>Hi <span class="user-mention" data-user-id="138448">@cuviper</span> , I've not forgotten about this, but I'm having a bit of trouble getting what should have been a simple fix to work. Changing <code>__rust_alloc</code>'s MemoryBuiltin in LLVM from:</p>
<div class="codehilite"><pre><span></span><code>case LibFunc_rust_alloc:
    return (NumParams == 3 &amp;&amp; FTy.getReturnType()-&gt;isPointerTy() &amp;&amp;
            FTy.getParamType(0)-&gt;isIntegerTy() &amp;&amp;
            FTy.getParamType(1)-&gt;isIntegerTy() &amp;&amp;
            FTy.getParamType(2)-&gt;isPointerTy());
</code></pre></div>
<p>To:</p>
<div class="codehilite"><pre><span></span><code>case LibFunc_rust_alloc:
    return (NumParams == 2 &amp;&amp; FTy.getReturnType()-&gt;isPointerTy() &amp;&amp;
            FTy.getParamType(0)-&gt;isIntegerTy() &amp;&amp;
            FTy.getParamType(1)-&gt;isIntegerTy());
</code></pre></div>
<p>Results in the <code>src/test/codegen/vec-optimizes-away.rs</code> test no longer being able to remove the alloc call and just return a const. I'm scratching my head a bit here because I'm at a loss. Could I be missing something obvious? I'm afraid I'm not that familiar with this part of rustc.</p>



<a name="224120504"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20fork%20prototypes%20rust_alloc%20with%203%20params/near/224120504" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20fork.20prototypes.20rust_alloc.20with.203.20params.html#224120504">(Jan 26 2021 at 23:39)</a>:</h4>
<p>is that the only one you changed? they might need to all work in concert</p>



<a name="224120505"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20fork%20prototypes%20rust_alloc%20with%203%20params/near/224120505" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20fork.20prototypes.20rust_alloc.20with.203.20params.html#224120505">(Jan 26 2021 at 23:39)</a>:</h4>
<p>but I'm just guessing</p>



<a name="224120868"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20fork%20prototypes%20rust_alloc%20with%203%20params/near/224120868" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Hughes <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20fork.20prototypes.20rust_alloc.20with.203.20params.html#224120868">(Jan 26 2021 at 23:44)</a>:</h4>
<p>ATM just this one as I've been trying to narrow it down, but I _think_ I had them all changed at one point and still had issues. Out of interest, is there a way to force the re-generation of the <code>.ll</code> input files for the <code>codegen/</code> tests? I've been seeing some funny behaviour with it being cached from stale builds when debugging this so have been recompiling liballoc each time to make sure (but that's slow on my machine!)</p>



<a name="224121113"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20fork%20prototypes%20rust_alloc%20with%203%20params/near/224121113" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20fork.20prototypes.20rust_alloc.20with.203.20params.html#224121113">(Jan 26 2021 at 23:47)</a>:</h4>
<p>I'm not sure</p>



<a name="224121413"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20fork%20prototypes%20rust_alloc%20with%203%20params/near/224121413" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Hughes <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20fork.20prototypes.20rust_alloc.20with.203.20params.html#224121413">(Jan 26 2021 at 23:50)</a>:</h4>
<p>no worries, i'll have another look and see if i can work out what's going on</p>



<a name="224958862"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20fork%20prototypes%20rust_alloc%20with%203%20params/near/224958862" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20fork.20prototypes.20rust_alloc.20with.203.20params.html#224958862">(Feb 03 2021 at 00:41)</a>:</h4>
<p><span class="user-mention silent" data-user-id="138448">cuviper</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/llvm.20fork.20prototypes.20rust_alloc.20with.203.20params/near/223950141">said</a>:</p>
<blockquote>
<p>oh my, it would be embarrassing if these have been so ineffective...</p>
</blockquote>
<p>There's a test for these in rust-lang/rust. I'm not sure how that could've been missed.</p>



<a name="224959543"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20fork%20prototypes%20rust_alloc%20with%203%20params/near/224959543" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20fork.20prototypes.20rust_alloc.20with.203.20params.html#224959543">(Feb 03 2021 at 00:50)</a>:</h4>
<p>Seems like the allocation optimisation still works <span aria-label="shrug" class="emoji emoji-1f937" role="img" title="shrug">:shrug:</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>